import {
  Base,
  PanelModel,
  SurveyModel,
  Serializer,
  ListModel,
  QuestionRadiogroupModel,
  QuestionTextModel,
  QuestionImageModel,
  QuestionRatingModel,
  QuestionDropdownModel,
  ItemValue,
  settings as surveySettings,
  QuestionPanelDynamicModel,
  CustomWidgetCollection,
  QuestionMatrixModel,
  Action,
  QuestionMatrixDynamicModel,
  QuestionCheckboxModel,
  ComponentCollection,
  QuestionCompositeModel,
  QuestionCustomModel,
  PageModel,
  ComputedUpdater,
  PopupDropdownViewModel,
  Question,
  SurveyElement,
} from "survey-core";
import { PageAdorner } from "../src/components/page";
import { QuestionAdornerViewModel } from "../src/components/question";
import { QuestionImageAdornerViewModel } from "../src/components/question-image";
import { QuestionDropdownAdornerViewModel } from "../src/components/question-dropdown";
import { SurveyElementAdornerBase } from "../src/components/survey-element-adorner-base";
import { PageNavigatorViewModel } from "../src/components/page-navigator/page-navigator";
import { TabDesignerPlugin } from "../src/components/tabs/designer-plugin";
import { TabTestPlugin } from "../src/components/tabs/test-plugin";
import { TabTranslationPlugin } from "../src/components/tabs/translation-plugin";
import { TabLogicPlugin } from "../src/components/tabs/logic-plugin";
import { TabJsonEditorTextareaPlugin } from "../src/components/tabs/json-editor-textarea";
import { TabJsonEditorAcePlugin } from "../src/components/tabs/json-editor-ace";
import { isTextInput } from "../src/creator-base";
import { ItemValueWrapperViewModel } from "../src/components/item-value";

import {
  getElementWrapperComponentData,
  getElementWrapperComponentName,
  getQuestionContentWrapperComponentName,
  isStringEditable
} from "../src/creator-base";
import { SurveyHelper } from "../src/survey-helper";
import { CreatorTester } from "./creator-tester";
import { EditorLocalization, editorLocalization, setupLocale } from "../src/editorLocalization";
import { ICreatorPlugin, settings } from "../src/creator-settings";
import { PropertyGridEditorCollection } from "../src/property-grid/index";
import { PropertyGridEditorMatrixItemValues } from "../src/property-grid/matrices";
import { ObjectSelector } from "../src/property-grid/object-selector";
import { TabDesignerViewModel } from "../src/components/tabs/designer";
import { ConfigureTablePropertyEditorEvent } from "../src/creator-events-api";
import { IQuestionToolboxItem } from "../src/toolbox";
import { ThemeTabPlugin } from "../src/components/tabs/theme-plugin";
import { TabbedMenuMode } from "../src/tabbed-menu";

export * from "../src/localization/french";

test("onModified is raised for mask settings", (): any => {
  const creator = new CreatorTester();
  creator.JSON = {
    "pages": [
      {
        "name": "page1",
        "elements": [
          {
            "type": "text",
            "name": "question1",
            "maskType": "numeric",
            "maskSettings": {
              "thousandsSeparator": "."
            }
          }
        ]
      }
    ]
  };
  let propName = "not triggered";
  creator.onModified.add((sender, options) => {
    propName = options.name;
  });
  const maskedQuestion = creator.survey.getQuestionByName("question1") as QuestionTextModel;
  (maskedQuestion.maskSettings as any).thousandsSeparator = "-";
  expect(propName).toBe("thousandsSeparator");
});

test("json editor default indent", (): any => {
  const creator = new CreatorTester();
  creator.JSON = { pages: [{ name: "page1" }] };
  expect(settings.jsonEditor.indentation).toBe(2);
  expect(creator.text).toBe("{\n  \"pages\": [\n    {\n      \"name\": \"page1\"\n    }\n  ]\n}");
});

test("onSetPropertyEditorOptions -> onConfigureTablePropertyEditor", (): any => {
  const creator = new CreatorTester();
  creator.JSON = { elements: [{ type: "dropdown", name: "q1", choices: [1, 2] }] };
  const question = creator.survey.getQuestionByName("q1");
  const callBackOptions = {
    allowAddRemoveItems: true,
    allowRemoveAllItems: true,
    allowBatchEdit: true
  };
  creator.onSetPropertyEditorOptionsCallback("choices", question, callBackOptions);
  expect(callBackOptions.allowBatchEdit).toBeTruthy();
  let onSetPropertyEditorOptions_allowBatchEdit = false;
  creator.onSetPropertyEditorOptions.add((sender: any, options: ConfigureTablePropertyEditorEvent) => {
    options.editorOptions.allowBatchEdit = onSetPropertyEditorOptions_allowBatchEdit;
  });
  creator.onSetPropertyEditorOptionsCallback("choices", question, callBackOptions);
  expect(callBackOptions.allowBatchEdit).toBeFalsy();
  callBackOptions.allowBatchEdit = true;
  onSetPropertyEditorOptions_allowBatchEdit = true;
  let onConfigureTablePropertyEditor_allowBatchEdit = true;
  creator.onConfigureTablePropertyEditor.add((sender: any, options: ConfigureTablePropertyEditorEvent) => {
    options.allowBatchEdit = onConfigureTablePropertyEditor_allowBatchEdit;
  });
  creator.onSetPropertyEditorOptionsCallback("choices", question, callBackOptions);
  expect(callBackOptions.allowBatchEdit).toBeTruthy();

  onSetPropertyEditorOptions_allowBatchEdit = false;
  creator.onSetPropertyEditorOptionsCallback("choices", question, callBackOptions);
  expect(callBackOptions.allowBatchEdit).toBeFalsy();
});

test("creator.onSurveyInstanceCreated from property Grid", () => {
  const creator = new CreatorTester();
  const selectedTypes = new Array<string>();
  creator.onSurveyInstanceCreated.add((sender, options) => {
    if (options.area === "property-grid") {
      if (options.element) {
        selectedTypes.push(options.element.getType());
      }
    }
  });
  creator.JSON = {
    elements: [
      { name: "q1", type: "text" },
      {
        name: "q2",
        type: "radiogroup"
      }
    ]
  };
  creator.selectQuestionByName("q1");
  creator.selectQuestionByName("q2");
  expect(selectedTypes).toStrictEqual(["survey", "text", "radiogroup"]);
});

test("creator.onSurveyInstanceSetupHandlers event", () => {
  const creator = new CreatorTester();
  let json = undefined;
  let counter = 0;
  creator.onSurveyInstanceSetupHandlers.add((sender, options) => {
    if (options.area === "property-grid") {
      json = options.survey.toJSON();
      counter ++;
    }
  });
  creator.JSON = {
    elements: [
      { name: "q1", type: "text" },
      {
        name: "q2",
        type: "radiogroup"
      }
    ]
  };
  expect(counter).toBe(1);
  creator.selectQuestionByName("q1");
  creator.selectQuestionByName("q2");
  expect(json).toStrictEqual({});
  expect(counter).toBe(3);
});

test("check tabResponsivenessMode property", () => {
  const creator = new CreatorTester();
  expect(creator.tabbedMenu.actions.every((action) => action.hasTitle)).toBeTruthy();
  expect(creator.tabbedMenu.actions.every((action) => !action.hasIcon)).toBeTruthy();
  creator.tabbedMenu.setMode(TabbedMenuMode.Icons);
  expect(creator.tabbedMenu.actions.every((action) => !action.hasTitle)).toBeTruthy();
  expect(creator.tabbedMenu.actions.every((action) => action.hasIcon)).toBeTruthy();
  creator.tabbedMenu.setMode(TabbedMenuMode.Titles);
  expect(creator.tabbedMenu.actions.every((action) => action.hasTitle)).toBeTruthy();
  expect(creator.tabbedMenu.actions.every((action) => !action.hasIcon)).toBeTruthy();
});

test("onModified options, on adding page and on copying page", () => {
  const creator = new CreatorTester();
  creator.JSON = {
    pages: [{ elements: [{ type: "text", name: "q1" }] }]
  };

  const modifiedOptions = new Array<any>();
  creator.onModified.add(function (survey, options) {
    modifiedOptions.push(options);
  });
  const newPage = new PageModel();
  newPage.name = "page2";
  creator.addPage(newPage);
  creator.copyPage(creator.survey.pages[0]);
  expect(modifiedOptions[0].type).toBe("PAGE_ADDED");
  expect(modifiedOptions[0].newValue.name).toBe("page2");
  expect(modifiedOptions[2].type).toBe("ELEMENT_COPIED");
  expect(modifiedOptions[2].newValue.name).toBe("page3");
});

test("ZoomIn/ZoomOut designer surface", (): any => {
  const creator = new CreatorTester();
  const designerTabModel = creator.getPlugin("designer").model as TabDesignerViewModel;
  expect(designerTabModel["surfaceScale"]).toBe(100);
  expect(creator.survey.widthScale).toBe(100);
  //expect(creator.themeVariables).toStrictEqual({});

  designerTabModel["scaleSurface"](10);
  expect(designerTabModel["surfaceScale"]).toBe(100);
  expect(creator.survey.widthScale).toBe(100);

  designerTabModel["scaleSurface"](200);
  expect(designerTabModel["surfaceScale"]).toBe(100);
  expect(creator.survey.widthScale).toBe(100);

  designerTabModel["maxSurfaceScaling"] = 200;
  designerTabModel["scaleSurface"](150);
  expect(creator.survey.widthScale).toBe(150);
  expect(designerTabModel["surfaceScale"]).toBe(150);

  expect(designerTabModel.surfaceCssVariables["--ctr-surface-base-unit"]).toBe("12px");
  expect(designerTabModel.surfaceCssVariables["--lbr-corner-radius-unit"]).toBe("12px");
  expect(designerTabModel.surfaceCssVariables["--lbr-font-unit"]).toBe("12px");
  expect(designerTabModel.surfaceCssVariables["--lbr-line-height-unit"]).toBe("12px");
  expect(designerTabModel.surfaceCssVariables["--lbr-size-unit"]).toBe("12px");
  expect(designerTabModel.surfaceCssVariables["--lbr-spacing-unit"]).toBe("12px");
  expect(designerTabModel.surfaceCssVariables["--lbr-stroke-unit"]).toBe("1.5px");
});

test("ZoomIn/ZoomOut actions limits", (): any => {
  const creator = new CreatorTester();
  const designerTabModel = creator.getPlugin("designer").model as TabDesignerViewModel;
  const zoomInAction = designerTabModel.surfaceToolbar.getActionById("zoomIn");
  const zoomOutAction = designerTabModel.surfaceToolbar.getActionById("zoomOut");
  const zoom100Action = designerTabModel.surfaceToolbar.getActionById("zoom100");

  expect(designerTabModel["surfaceScale"]).toBe(100);
  expect(creator.survey.widthScale).toBe(100);

  zoomInAction.action();
  expect(designerTabModel["surfaceScale"]).toBe(100);
  expect(creator.survey.widthScale).toBe(100);

  zoomOutAction.action();
  expect(designerTabModel["surfaceScale"]).toBe(90);
  expect(creator.survey.widthScale).toBe(90);

  zoomOutAction.action();
  zoomOutAction.action();
  zoomOutAction.action();
  zoomOutAction.action();
  zoomOutAction.action();
  zoomOutAction.action();
  expect(designerTabModel["surfaceScale"]).toBe(30);
  expect(creator.survey.widthScale).toBe(30);

  zoomOutAction.action();
  expect(designerTabModel["surfaceScale"]).toBe(20);
  expect(creator.survey.widthScale).toBe(20);

  zoomOutAction.action();
  expect(designerTabModel["surfaceScale"]).toBe(20);
  expect(creator.survey.widthScale).toBe(20);

  zoom100Action.action();
  expect(designerTabModel["surfaceScale"]).toBe(100);
  expect(creator.survey.widthScale).toBe(100);
});

test("propertyGridNavigationMode property", (): any => {
  const creator = new CreatorTester();
  creator.propertyGridNavigationMode = "buttons";
  expect(creator.showOneCategoryInPropertyGrid).toBeTruthy();
  creator.propertyGridNavigationMode = "accordion";
  expect(creator.showOneCategoryInPropertyGrid).toBeFalsy();

  creator.showOneCategoryInPropertyGrid = true;
  expect(creator.propertyGridNavigationMode).toBe("buttons");
  creator.showOneCategoryInPropertyGrid = false;
  expect(creator.propertyGridNavigationMode).toBe("accordion");
});

test("Plugin showOneCategoryInPropertyGrid by default", (): any => {
  const creator = new CreatorTester({ showThemeTab: true, showTranslationTab: true });
  const designerPlugin = <TabDesignerPlugin>creator.getPlugin("designer");
  const themePlugin: ThemeTabPlugin = <ThemeTabPlugin>creator.getPlugin("theme");
  const translationPlugin = <TabTranslationPlugin>(creator.getPlugin("translation"));
  expect(creator.showOneCategoryInPropertyGrid).toBeTruthy();
  expect(designerPlugin.showOneCategoryInPropertyGrid).toBeTruthy();
  expect(themePlugin.showOneCategoryInPropertyGrid).toBeTruthy();
  expect(translationPlugin.showOneCategoryInPropertyGrid).toBeTruthy();

  creator.propertyGridNavigationMode = "accordion";
  expect(creator.showOneCategoryInPropertyGrid).toBeFalsy();
  expect(designerPlugin.showOneCategoryInPropertyGrid).toBeFalsy();
  expect(themePlugin.showOneCategoryInPropertyGrid).toBeFalsy();
  expect(translationPlugin.showOneCategoryInPropertyGrid).toBeFalsy();
});

test("Set propertyGridNavigationMode property by options", (): any => {
  const creator = new CreatorTester({
    propertyGridNavigationMode: "accordion",
    showThemeTab: true,
    showTranslationTab: true
  });
  const designerPlugin = <TabDesignerPlugin>creator.getPlugin("designer");
  const themePlugin: ThemeTabPlugin = <ThemeTabPlugin>creator.getPlugin("theme");
  const translationPlugin = <TabTranslationPlugin>(creator.getPlugin("translation"));
  expect(creator.showOneCategoryInPropertyGrid).toBeFalsy();
  expect(designerPlugin.showOneCategoryInPropertyGrid).toBeFalsy();
  expect(themePlugin.showOneCategoryInPropertyGrid).toBeFalsy();
  expect(translationPlugin.showOneCategoryInPropertyGrid).toBeFalsy();

  creator.propertyGridNavigationMode = "buttons";
  expect(creator.showOneCategoryInPropertyGrid).toBeTruthy();
  expect(designerPlugin.showOneCategoryInPropertyGrid).toBeTruthy();
  expect(themePlugin.showOneCategoryInPropertyGrid).toBeTruthy();
  expect(translationPlugin.showOneCategoryInPropertyGrid).toBeTruthy();
});
test("creator theme & settings property grids & creator.locale, bug#7130", () => {
  const creator = new CreatorTester();
  const designerPlugin = <TabDesignerPlugin>creator.getPlugin("designer");
  expect(designerPlugin["themePropertyGrid"].survey.getQuestionByName("themeName").title).toBe("Theme name");
  creator.locale = "fr";
  expect(designerPlugin["themePropertyGrid"].survey.getQuestionByName("themeName").title).toBe("Nom du thème"); // eslint-disable-line surveyjs/eslint-plugin-i18n/only-english-or-code
  creator.locale = "en";
});

test("showSurfaceTools", (): any => {
  const creator = new CreatorTester();
  creator.expandCollapseButtonVisibility = "never";
  creator.allowZoom = false;
  const designerTabModel = creator.getPlugin("designer").model as TabDesignerViewModel;
  expect(designerTabModel.showSurfaceTools).toBeFalsy();

  creator.JSON = { pages: [{ name: "page1" }, { name: "page2" }] };
  expect(designerTabModel.showSurfaceTools).toBeTruthy();

  creator.isMobileView = true;
  expect(designerTabModel.showSurfaceTools).toBeFalsy();

  creator.isMobileView = false;
  expect(designerTabModel.showSurfaceTools).toBeTruthy();

  creator.JSON = { pages: [{ name: "page1" }] };
  expect(designerTabModel.showSurfaceTools).toBeFalsy();

  creator.expandCollapseButtonVisibility = "always";
  expect(designerTabModel.showSurfaceTools).toBeTruthy();
});

test("Designer surface css classes", (): any => {
  const savedNewJSON = settings.defaultNewSurveyJSON;
  settings.defaultNewSurveyJSON = {};
  const creator = new CreatorTester();
  creator.expandCollapseButtonVisibility = "never";
  const designerTabModel = creator.getPlugin("designer").model as TabDesignerViewModel;
  expect(designerTabModel.getRootCss()).toBe("sd-root-modern svc-tab-designer--with-surface-tools svc-tab-designer--with-placeholder svc-tab-designer--standard-mode");

  creator.allowZoom = false;
  expect(designerTabModel.getRootCss()).toBe("sd-root-modern svc-tab-designer--with-placeholder svc-tab-designer--standard-mode");

  creator.JSON = { pages: [{ name: "page1" }] };
  expect(designerTabModel.getRootCss()).toBe("sd-root-modern svc-tab-designer--standard-mode");

  creator.expandCollapseButtonVisibility = "always";
  expect(designerTabModel.getRootCss()).toBe("sd-root-modern svc-tab-designer--with-surface-tools svc-tab-designer--standard-mode");

  creator.expandCollapseButtonVisibility = "never";
  creator.JSON = { pages: [{ name: "page1" }, { name: "page2" }] };
  expect(designerTabModel.getRootCss()).toBe("sd-root-modern svc-tab-designer--with-surface-tools svc-tab-designer--standard-mode");

  settings.defaultNewSurveyJSON = savedNewJSON;
});

test("Update showPlaceholder calls updateSurveyScaleStartDimensions and resets scale start dimensions", (): any => {
  const creator = new CreatorTester();
  const designerPlugin = <TabDesignerPlugin>(creator.getPlugin("designer"));
  designerPlugin.activate();
  const model = designerPlugin.model;
  (model as any).checkNewPage();
  expect(model.showPlaceholder).toBeTruthy();

  creator.survey.setResponsiveStartWidth(1000);
  creator.survey.setStaticStartWidth(1000);
  expect(creator.survey.responsiveStartWidth).toBe(1000);
  expect(creator.survey.staticStartWidth).toBe(1000);

  creator.survey.addNewPage();
  expect(model.showPlaceholder).toBeFalsy();
  expect(creator.survey.responsiveStartWidth).toBeUndefined();
  expect(creator.survey.staticStartWidth).toBeUndefined();
});

test("allowDragPages respects the pageEditMode", (): any => {
  const creator = new CreatorTester();
  expect(creator.allowDragPages).toBeTruthy();
  expect(creator.pageEditMode).toBe("standard");

  creator.allowDragPages = false;
  expect(creator.allowDragPages).toBeFalsy();
  expect(creator.pageEditMode).toBe("standard");

  creator.allowDragPages = true;
  expect(creator.allowDragPages).toBeTruthy();
  expect(creator.pageEditMode).toBe("standard");

  creator.pageEditMode = "bypage";
  expect(creator.allowDragPages).toBeFalsy();
  expect(creator.pageEditMode).toBe("bypage");
});
test("Show editor tab for pageEditMode equals to 'bypage', Bug#", (): any => {
  const creator = new CreatorTester({ pageEditMode: "bypage" });
  creator.JSON = { pages: [{ name: "page1" }] };
  expect(creator.pageEditMode).toBe("bypage");
  expect(creator.showJSONEditorTab).toBeTruthy();
  expect(creator.tabbedMenu.getActionById("designer").isVisible).toBeTruthy();
  expect(creator.tabbedMenu.getActionById("json").isVisible).toBeTruthy();
});
test("onElementAllowOperations for pages and allowDragging in page adorner", (): any => {
  const creator = new CreatorTester();
  creator.JSON = { elements: [{ type: "text" }] };
  const reason: Array<boolean> = [];
  let disableDrag = false;
  creator.onElementAllowOperations.add(function (sender, options) {
    if (options.element.getType() == "page") {
      reason.push(options.allowDrag);
      if (disableDrag) {
        options.allowDrag = false;
      }
    }
  });

  const pageAdorner = new PageAdorner(creator, creator.survey.pages[0]);
  expect(creator.allowDragPages).toBeTruthy();
  expect(pageAdorner.allowDragging).toBeTruthy();
  expect(reason).toHaveLength(1);
  expect(reason[0]).toBeTruthy();

  creator.allowDragPages = false;
  pageAdorner["updateActionsProperties"]();

  expect(creator.allowDragPages).toBeFalsy();
  expect(pageAdorner.allowDragging).toBeFalsy();
  expect(reason).toHaveLength(2);
  expect(reason[1]).toBeFalsy();

  creator.allowDragPages = true;
  disableDrag = true;
  pageAdorner["updateActionsProperties"]();

  expect(creator.allowDragPages).toBeTruthy();
  expect(pageAdorner.allowDragging).toBeFalsy();
  expect(reason).toHaveLength(3);
  expect(reason[2]).toBeTruthy();
});

test("Show/hide creator settings", (): any => {
  const creator = new CreatorTester();
  expect(creator.sidebar.activePage).toBe("propertyGridPlaceholder");

  creator.openCreatorThemeSettings();
  expect(creator.sidebar.activePage).toBe("creatorTheme");

  creator.closeCreatorThemeSettings();
  expect(creator.sidebar.activePage).toBe("propertyGridPlaceholder");
});

test("activatePropertyGridCategory function", (): any => {
  const creator = new CreatorTester();
  let propertyGrid = creator["designerPropertyGrid"];
  expect(propertyGrid.survey.currentPage.name).toBe("general");

  creator.activatePropertyGridCategory("pages");
  expect(propertyGrid.survey.currentPage.name).toBe("pages");
});

test("creator set theme should update headerView survey property", (): any => {
  const creator = new CreatorTester();
  expect(creator.survey.headerView).toBe("advanced");
  creator.theme = {};
  expect(creator.survey.headerView).toBe("advanced");
  creator.theme = { headerView: "basic" };
  expect(creator.survey.headerView).toBe("basic");
});

test("creator set theme should update headerView survey property", (): any => {
  const creator = new CreatorTester({
    clearTranslationsOnSourceTextChange: true
  });
  creator.JSON = {
    elements: [
      {
        type: "text", name: "q1", title: { default: "my question", de: "de: my question" }
      },
      {
        type: "checkbox", name: "my question", title: { de: "de: my question" },
        choices: [
          { value: 1, text: { default: "item1", de: "de-item" } },
          { value: "item2", text: { de: "de-item2" } }
        ]
      },
      {
        type: "matrixdynamic", name: "q3", columns: [
          { name: "col1", title: { default: "col1", de: "de-col1" } },
          { name: "col2", title: { de: "de-col2" } }
        ]
      }
    ]
  };
  expect(creator.clearTranslationsOnSourceTextChange).toBeTruthy();
  const q1 = creator.survey.getQuestionByName("q1");
  const q2 = creator.survey.getQuestionByName("my question");
  const columns = creator.survey.getQuestionByName("q3").columns;
  const choices = q2.choices;
  expect(q1.locTitle.getLocaleText("de")).toBe("de: my question");
  expect(q2.locTitle.getLocaleText("de")).toBe("de: my question");
  expect(choices[0].locText.getLocaleText("de")).toBe("de-item");
  expect(choices[1].locText.getLocaleText("de")).toBe("de-item2");
  expect(columns[0].locTitle.getLocaleText("de")).toBe("de-col1");
  expect(columns[1].locTitle.getLocaleText("de")).toBe("de-col2");
  q1.name = "q1_new";
  q2.name = "my question_new";
  expect(q1.locTitle.getLocaleText("de")).toBe("de: my question");
  expect(q2.locTitle.getLocaleText("de")).toBeFalsy();

  columns[0].name = "col1_new";
  columns[1].name = "col2_new";
  expect(columns[0].locTitle.getLocaleText("de")).toBe("de-col1");
  expect(columns[1].locTitle.getLocaleText("de")).toBeFalsy();

  choices[0].value = "item1_new";
  choices[1].value = "item2_new";
  expect(choices[0].locText.getLocaleText("de")).toBe("de-item");
  expect(choices[1].locText.getLocaleText("de")).toBeFalsy();

  q1.title = "my question_new";
  expect(q1.locTitle.getLocaleText("de")).toBeFalsy();

  columns[0].title = "col1_new";
  expect(columns[0].locTitle.getLocaleText("de")).toBeFalsy();

  choices[0].text = "item1_new";
  expect(choices[0].locText.getLocaleText("de")).toBeFalsy();

  creator.survey.locale = "fr";
  q1.locTitle.setLocaleText("de", "de: my question_new");
  q2.locTitle.setLocaleText("de", "de: my question_new");
  q1.title = "fr: my question_new";
  q1.title = "fr: my question_new-1";
  expect(q1.locTitle.getJson()).toStrictEqual({
    default: "my question_new",
    de: "de: my question_new",
    fr: "fr: my question_new-1"
  });
  q2.name = "q2_new2";
  expect(q2.locTitle.getJson()).toStrictEqual({
    de: "de: my question_new"
  });
});

test("ConvertTo and addNewQuestion for panel with maxPanelNestingLevel set", (): any => {
  const creator = new CreatorTester({ maxPanelNestingLevel: 0 });
  creator.JSON = {
    elements: [
      {
        type: "panel", name: "panel1",
        elements: [
          {
            type: "panel", name: "panel3",
            elements: [
              { type: "panel", name: "panel5" },
              { type: "paneldynamic", name: "panel6" }
            ]
          },
          { type: "paneldynamic", name: "panel4" }
        ]
      },
      { type: "paneldynamic", name: "panel2" }
    ]
  };
  expect(creator.maxNestedPanels).toBe(-1);
  expect(creator.maxPanelNestingLevel).toBe(0);
  expect(creator.dragDropSurveyElements.maxNestedPanels).toBe(-1);
  expect(creator.dragDropSurveyElements.maxPanelNestingLevel).toBe(0);
  creator.maxPanelNestingLevel = -1;
  expect(creator.dragDropSurveyElements.maxPanelNestingLevel).toBe(-1);
  const panel1 = creator.survey.getPanelByName("panel1");
  const panel2 = creator.survey.getQuestionByName("panel2");
  const panel3 = creator.survey.getPanelByName("panel3");
  const panel4 = creator.survey.getQuestionByName("panel4");
  const panel5 = creator.survey.getPanelByName("panel5");
  const panel6 = creator.survey.getQuestionByName("panel6");
  const itemCount = creator.getAvailableToolboxItems().length;
  expect(itemCount).toBe(22);
  const panel6Model = new QuestionAdornerViewModel(creator, panel6, undefined);
  const panel5Model = new QuestionAdornerViewModel(creator, panel5, undefined);
  expect(creator.getAvailableToolboxItems(panel5)).toHaveLength(itemCount);
  expect(creator.getAvailableToolboxItems(panel6)).toHaveLength(itemCount);
  creator.maxPanelNestingLevel = 3;
  expect(creator.dragDropSurveyElements.maxPanelNestingLevel).toBe(3);
  expect(creator.getAvailableToolboxItems(panel5)).toHaveLength(itemCount);
  expect(creator.getAvailableToolboxItems(panel6)).toHaveLength(itemCount);
  expect(panel6Model.getConvertToTypesActions()).toHaveLength(itemCount);
  expect(panel5Model.getConvertToTypesActions()).toHaveLength(itemCount);
  creator.maxPanelNestingLevel = 2;
  expect(creator.dragDropSurveyElements.maxPanelNestingLevel).toBe(2);
  expect(creator.getAvailableToolboxItems(panel5, false)).toHaveLength(itemCount);
  expect(creator.getAvailableToolboxItems(panel6, false)).toHaveLength(itemCount);
  expect(creator.getAvailableToolboxItems(panel5)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel6)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel3)).toHaveLength(itemCount);
  expect(creator.getAvailableToolboxItems(panel4)).toHaveLength(itemCount);
  expect(creator.getAvailableToolboxItems(panel2)).toHaveLength(itemCount);
  expect(creator.getAvailableToolboxItems(panel1)).toHaveLength(itemCount);
  expect(panel6Model.getConvertToTypesActions()).toHaveLength(itemCount);
  expect(panel5Model.getConvertToTypesActions()).toHaveLength(itemCount);
  expect(creator.getAvailableToolboxItems()).toHaveLength(itemCount);
  creator.maxPanelNestingLevel = 1;
  expect(creator.dragDropSurveyElements.maxPanelNestingLevel).toBe(1);
  expect(creator.getAvailableToolboxItems(panel5, false)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel6, false)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel5)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel6)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel3, false)).toHaveLength(itemCount);
  expect(creator.getAvailableToolboxItems(panel4, false)).toHaveLength(itemCount);
  expect(creator.getAvailableToolboxItems(panel3)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel4)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel2)).toHaveLength(itemCount);
  expect(creator.getAvailableToolboxItems(panel1)).toHaveLength(itemCount);
  expect(panel6Model.getConvertToTypesActions()).toHaveLength(itemCount - 2);
  expect(panel5Model.getConvertToTypesActions()).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems()).toHaveLength(itemCount);
  creator.maxPanelNestingLevel = 0;
  expect(creator.dragDropSurveyElements.maxPanelNestingLevel).toBe(0);
  expect(creator.getAvailableToolboxItems(panel5, false)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel6, false)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel5)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel6)).toHaveLength(itemCount - 2);
  expect(panel6Model.getConvertToTypesActions()).toHaveLength(itemCount - 2);
  expect(panel5Model.getConvertToTypesActions()).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel3, false)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel4, false)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel3)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel4)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel1, false)).toHaveLength(itemCount);
  expect(creator.getAvailableToolboxItems(panel2, false)).toHaveLength(itemCount);
  expect(creator.getAvailableToolboxItems(panel1)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel2)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems()).toHaveLength(itemCount);
});

test("addNewQuestion popup menu for first level panels and paneldynamics", (): any => {
  const creator = new CreatorTester({ maxPanelNestingLevel: 0 });
  creator.JSON = {
    "pages": [
      {
        "name": "page1",
        "elements": [
          {
            "type": "panel",
            "name": "panel1"
          },
          {
            "type": "paneldynamic",
            "name": "question1"
          }
        ]
      }
    ],
    "headerView": "advanced"
  };
  expect(creator.maxNestedPanels).toBe(-1);
  expect(creator.maxPanelNestingLevel).toBe(0);
  const panel = creator.survey.getPanelByName("panel1");
  const paneldynamic = creator.survey.getQuestionByName("question1");
  const itemCount = creator.getAvailableToolboxItems().length;
  expect(itemCount).toBe(22);
  expect(creator.getAvailableToolboxItems()).toHaveLength(itemCount);
  // Add New (create child) action
  expect(creator.getAvailableToolboxItems(panel)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(paneldynamic)).toHaveLength(itemCount - 2);
  // Convert To action
  expect(creator.getAvailableToolboxItems(panel, false)).toHaveLength(itemCount);
  expect(creator.getAvailableToolboxItems(paneldynamic, false)).toHaveLength(itemCount);
});

test("getAvailableToolboxItems isAllowedToAdd forbiddenNestedElements", (): any => {
  const creator = new CreatorTester();
  creator.JSON = {
    elements: [
      { type: "panel", name: "panel1", elements: [{ type: "text", name: "question1" }] },
      { type: "paneldynamic", name: "panel2", templateElements: [{ type: "text", name: "question2" }] }
    ]
  };
  expect(creator.forbiddenNestedElements).toBe(undefined);
  const panel1 = creator.survey.getPanelByName("panel1");
  const panel2 = creator.survey.getQuestionByName("panel2");
  const question1 = creator.survey.getQuestionByName("question1");
  const question2 = panel2.template.getQuestionByName("question2");
  const itemCount = creator.getAvailableToolboxItems().length;
  expect(itemCount).toBe(22);
  creator.forbiddenNestedElements = { "panel": ["expression"], "paneldynamic": ["file", "radiogroup"] };
  expect(creator.getAvailableToolboxItems(panel1, false)).toHaveLength(itemCount - 1);
  expect(creator.getAvailableToolboxItems(panel2, false)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(panel1)).toHaveLength(itemCount - 1);
  expect(creator.getAvailableToolboxItems(panel2)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(question1, false)).toHaveLength(itemCount - 1);
  expect(creator.getAvailableToolboxItems(question1)).toHaveLength(itemCount - 1);
  expect(creator.getAvailableToolboxItems(question2, false)).toHaveLength(itemCount - 2);
  expect(creator.getAvailableToolboxItems(question2)).toHaveLength(itemCount - 2);
});

test("getAvailableToolboxItems isAllowedToAdd forbiddenNestedElements #6973", (): any => {
  const creator = new CreatorTester();
  creator.forbiddenNestedElements = {
    panel: ["panel"],
    paneldynamic: ["panel", "paneldynamic"],
  };
  creator.JSON = {
    elements: [
      { type: "panel", name: "panel1", elements: [{ type: "text", name: "question1" }] },
      { type: "paneldynamic", name: "panel2", templateElements: [{ type: "text", name: "question2" }] }
    ]
  };
  const itemCount = creator.getAvailableToolboxItems().length;
  expect(itemCount).toBe(22);
  const panel2 = creator.survey.getQuestionByName("panel2");
  expect(creator.getAvailableToolboxItems(panel2, false)).toHaveLength(itemCount - 2);
  const innerPanel = panel2.template;
  const ownerElement = creator._getActualElementToAddNewElements(innerPanel);
  expect(ownerElement).toBe(panel2);
  expect(creator.getAvailableToolboxItems(ownerElement, false)).toHaveLength(itemCount - 2);
});

test("Preserve defaultAddQuestionType", (): any => {
  surveySettings.animationEnabled = false;
  const creator = new CreatorTester();
  creator.JSON = {
    pages: [{ name: "page1" }]
  };
  const survey: SurveyModel = creator.survey;
  settings.designer.defaultAddQuestionType = "radiogroup";
  creator.rememberLastQuestionType = false;
  const pageAdorner = new PageAdorner(creator, survey.pages[0]);
  const questionTypeSelectorListModel = pageAdorner.questionTypeSelectorModel.popupModel.contentComponentData.model as ListModel;
  const actionPopupViewModel = new PopupDropdownViewModel(pageAdorner.questionTypeSelectorModel.popupModel); // need for popupModel.onShow
  pageAdorner.questionTypeSelectorModel.popupModel.show();

  expect(pageAdorner.currentAddQuestionType).toEqual("");
  expect(creator.currentAddQuestionType).toEqual("");
  pageAdorner.addNewQuestion(pageAdorner, undefined as any);
  const question1 = <QuestionRadiogroupModel>survey.getAllQuestions()[0];
  expect(question1.getType()).toEqual("radiogroup");
  expect(creator.addNewQuestionText).toEqual("Add Question");

  expect(questionTypeSelectorListModel.actions[10].id).toEqual("text");
  questionTypeSelectorListModel.onItemClick(questionTypeSelectorListModel.actions[10]);
  const question2 = <QuestionRadiogroupModel>survey.getAllQuestions()[1];
  expect(question2.getType()).toEqual("text");
  expect(pageAdorner.currentAddQuestionType).toEqual("");
  expect(creator.currentAddQuestionType).toEqual("");
  expect(creator.addNewQuestionText).toEqual("Add Question");

  pageAdorner.addNewQuestion(pageAdorner, undefined as any);
  const question3 = <QuestionRadiogroupModel>survey.getAllQuestions()[2];
  expect(question3.getType()).toEqual("radiogroup");
  expect(pageAdorner.currentAddQuestionType).toEqual("");
  expect(creator.currentAddQuestionType).toEqual("");
  expect(creator.addNewQuestionText).toEqual("Add Question");
  settings.designer.defaultAddQuestionType = "text";
});
test("Preserve defaultAddQuestionType in Creator options, Issue#7291", (): any => {
  surveySettings.animationEnabled = false;
  const creator = new CreatorTester();
  creator.JSON = {
    pages: [{ name: "page1" }]
  };
  const survey: SurveyModel = creator.survey;
  creator.defaultAddQuestionType = "radiogroup";
  creator.rememberLastQuestionType = false;
  const pageAdorner = new PageAdorner(creator, survey.pages[0]);
  const questionTypeSelectorListModel = pageAdorner.questionTypeSelectorModel.popupModel.contentComponentData.model as ListModel;
  const actionPopupViewModel = new PopupDropdownViewModel(pageAdorner.questionTypeSelectorModel.popupModel); // need for popupModel.onShow
  pageAdorner.questionTypeSelectorModel.popupModel.show();

  expect(pageAdorner.currentAddQuestionType).toEqual("");
  expect(creator.currentAddQuestionType).toEqual("");
  pageAdorner.addNewQuestion(pageAdorner, undefined as any);
  const question1 = <QuestionRadiogroupModel>survey.getAllQuestions()[0];
  expect(question1.getType()).toEqual("radiogroup");
  expect(creator.addNewQuestionText).toEqual("Add Question");

  expect(questionTypeSelectorListModel.actions[10].id).toEqual("text");
  questionTypeSelectorListModel.onItemClick(questionTypeSelectorListModel.actions[10]);
  const question2 = <QuestionRadiogroupModel>survey.getAllQuestions()[1];
  expect(question2.getType()).toEqual("text");
  expect(pageAdorner.currentAddQuestionType).toEqual("");
  expect(creator.currentAddQuestionType).toEqual("");
  expect(creator.addNewQuestionText).toEqual("Add Question");

  pageAdorner.addNewQuestion(pageAdorner, undefined as any);
  const question3 = <QuestionRadiogroupModel>survey.getAllQuestions()[2];
  expect(question3.getType()).toEqual("radiogroup");
  expect(pageAdorner.currentAddQuestionType).toEqual("");
  expect(creator.currentAddQuestionType).toEqual("");
  expect(creator.addNewQuestionText).toEqual("Add Question");
});

test("License text for default locale and another default locale", (): any => {
  expect(editorLocalization.getLocale()).toBeDefined();
  expect(editorLocalization.getString("survey.license")).toBe(editorLocalization.getLocaleStrings("en").survey.license);
  let creator = new CreatorTester();
  expect(creator.licenseText).toBe(editorLocalization.getLocaleStrings("en").survey.license);

  editorLocalization.defaultLocale = "fr";
  creator = new CreatorTester();
  expect(creator.licenseText).toBe(editorLocalization.getLocaleStrings("en").survey.license);
  expect(editorLocalization.getLocale()).toBeDefined();
  expect(editorLocalization.getString("survey.license")).toBe(editorLocalization.getLocaleStrings("en").survey.license);

  setupLocale({ localeCode: "fr", strings: { survey: {} } });
  creator = new CreatorTester();
  expect(creator.licenseText).toBe(editorLocalization.getLocaleStrings("en").survey.license);
  expect(editorLocalization.getLocale()).toBeDefined();
  expect(editorLocalization.getString("survey.license")).toBe(editorLocalization.getLocaleStrings("en").survey.license);

  setupLocale({ localeCode: "fr", strings: { survey: { license: "My license string" } } });
  creator = new CreatorTester();
  expect(creator.licenseText).toBe("My license string");
  expect(editorLocalization.getLocale()).toBeDefined();
  expect(editorLocalization.getString("survey.license")).toBe("My license string");

  editorLocalization.defaultLocale = "en";
});

test("isStringEditable", (): any => {
  expect(isStringEditable({ isContentElement: true }, "")).toBeFalsy();
  expect(isStringEditable({}, "")).toBeTruthy();
  expect(
    isStringEditable({ isEditableTemplateElement: true }, "")
  ).toBeTruthy();
  expect(
    isStringEditable(
      { isContentElement: true, isEditableTemplateElement: true },
      ""
    )
  ).toBeTruthy();
});
test("isStringEditable for matrix dynamic", (): any => {
  const matrix = new QuestionMatrixDynamicModel("q1");
  matrix.addColumn("col1");
  matrix.rowCount = 1;
  expect(isStringEditable(matrix.columns[0].templateQuestion, "")).toBeTruthy();
  expect(isStringEditable(matrix.visibleRows[0].cells[0].question, "")).toBeFalsy();
});
test("onGetIsStringEditable", (): any => {
  const creator = new CreatorTester();
  let lastEditableValue;
  let callCount = 0;
  let newValue;
  creator.onAllowInplaceEdit.add((s, o) => {
    lastEditableValue = o.allow;
    callCount++;
    if (newValue !== undefined) {
      o.allow = newValue;
    }
  });
  expect(lastEditableValue).toBeUndefined();
  expect(callCount).toBe(0);

  expect(creator.isStringInplacelyEditable({ isContentElement: true } as any, "")).toBeFalsy();
  expect(lastEditableValue).toBeFalsy();
  expect(callCount).toBe(1);

  expect(creator.isStringInplacelyEditable({ } as any, "")).toBeTruthy();
  expect(lastEditableValue).toBeTruthy();
  expect(callCount).toBe(2);

  newValue = true;
  expect(creator.isStringInplacelyEditable({ isContentElement: true } as any, "")).toBeTruthy();
  expect(lastEditableValue).toBeFalsy();
  expect(callCount).toBe(3);
});
test("Restrict users from adding more than a specified number of questions to a survey Issue#7122", (): any => {
  const creator = new CreatorTester();
  creator.onAllowAddElement.add((sender, options) => {
    if (options.name === "comment") {
      const qs = creator.survey.getAllQuestions(true, true, true);
      qs.filter(q => q.getType() === "comment");
      options.allow = qs.length < 2;
    }
  });
  const action = creator.toolbox.getActionById("comment");
  expect(action).toBeTruthy();
  expect(creator.survey.getAllQuestions().length).toBe(0);
  expect(action.enabled).toBeTruthy();
  creator.clickToolboxItem((action.json));
  expect(creator.survey.getAllQuestions().length).toBe(1);
  const pAdorner = new PageAdorner(creator, creator.survey.pages[0]);
  const pDuplicateAction = pAdorner.actionContainer.getActionById("duplicate");
  const qAdorner = new QuestionAdornerViewModel(creator, creator.survey.getAllQuestions()[0], undefined);
  const qDuplicateAction = qAdorner.actionContainer.getActionById("duplicate");
  expect(qDuplicateAction).toBeTruthy();
  expect(qDuplicateAction.isVisible).toBeTruthy();
  expect(pDuplicateAction).toBeTruthy();
  expect(pDuplicateAction.isVisible).toBeTruthy();
  expect(action.enabled).toBeTruthy();
  creator.clickToolboxItem((action.json));
  expect(creator.survey.getAllQuestions().length).toBe(2);
  expect(action.enabled).toBeFalsy();
  expect(qDuplicateAction.isVisible).toBeFalsy();
  expect(pDuplicateAction.isVisible).toBeFalsy();

  creator.deleteElement(creator.survey.getAllQuestions()[0]);
  expect(action.enabled).toBeTruthy();
  expect(qDuplicateAction.isVisible).toBeTruthy();
  expect(pDuplicateAction.isVisible).toBeTruthy();

  expect(pAdorner.currentAddQuestionType).toBe("");
  pAdorner.currentAddQuestionType = "comment";
  pAdorner.addNewQuestion(pAdorner, undefined);
  expect(creator.survey.getAllQuestions().length).toBe(2);
  expect(action.enabled).toBeFalsy();
  expect(qDuplicateAction.isVisible).toBeFalsy();
  expect(pAdorner.currentAddQuestionType).toBe("");
  creator.JSON = { };
  expect(action.enabled).toBeTruthy();
});
test("Should not modify expression properties  on copying questions inside the dynamic panel, Bug#7223", (): any => {
  const creator = new CreatorTester();
  creator.JSON = {
    "elements": [
      {
        "type": "paneldynamic",
        "name": "panel1",
        "templateElements": [
          {
            "type": "boolean",
            "name": "q1"
          },
          {
            "type": "text",
            "name": "q2",
            "visibleIf": "{panel.q1} = true"
          }
        ]
      }
    ]
  };
  const panel1 = (creator.survey.getQuestionByName("panel1") as QuestionPanelDynamicModel).template;
  const q2 = panel1.getQuestionByName("q2");
  expect(q2.visibleIf).toBe("{panel.q1} = true");
  const q1 = panel1.getQuestionByName("q1");
  creator.copyQuestion(q1, true);
  expect(q2.visibleIf).toBe("{panel.q1} = true");
});

test("survey in theme tab shouldn't show timer panel", () => {
  const creator = new CreatorTester();
  const survey = creator.createSurvey({
    "pages": [
      {
        "name": "page1",
        "elements": [
          {
            "type": "text",
            "name": "question1"
          }
        ]
      }
    ],
    "showTimer": true,
    "timeLimit": 5,
    "headerView": "advanced"
  }, "theme");
  expect(survey.getPanelByName("showTimer")).toBeFalsy();
});

test("option to hide sidebar", () => {
  const creator = new CreatorTester();
  expect(creator.isSidebarVisible).toBeTruthy();
  creator.removeSidebar = true;
  expect(creator.isSidebarVisible).toBeFalsy();
  creator.removeSidebar = false;
  expect(creator.isSidebarVisible).toBeTruthy();
  creator.sidebar = undefined;
  expect(creator.isSidebarVisible).toBeFalsy();
});

test("option to hide settings action", () => {
  const creator = new CreatorTester();
  creator.JSON = { "pages": [{ "name": "page1", "elements": [{ "type": "text", "name": "question1" }] }] };
  creator.sidebar.flyoutMode = true;
  const question = creator.survey.getQuestionByName("question1");
  const questionAdorner = new QuestionAdornerViewModel(creator, question, <any>undefined);
  creator.selectElement(question);

  const settingsAction = questionAdorner.actionContainer.getActionById("settings");
  const toolbarSettings = creator.toolbar.getActionById("svd-settings");
  expect(toolbarSettings.isVisible).toBeTruthy();
  expect(settingsAction.isVisible).toBeTruthy();

  creator.removeSidebar = true;
  creator.selectElement(creator.survey.pages[0]);
  creator.selectElement(question);
  expect(toolbarSettings.isVisible).toBeFalsy();
  expect(settingsAction.isVisible).toBeFalsy();
});

test("Test inplaceEditChoiceValues <> inplaceEditForValues compatibility", (): any => {
  const creator = new CreatorTester();
  creator.inplaceEditChoiceValues = true;
  expect(creator.inplaceEditForValues).toEqual(true);
  creator.inplaceEditForValues = false;
  expect(creator.inplaceEditChoiceValues).toEqual(false);
});

test("Test showObjectTitles <> useElementTitles compatibility", () => {
  const creator = new CreatorTester();
  creator.useElementTitles = true;
  expect(creator.showObjectTitles).toEqual(true);
  creator.showObjectTitles = false;
  expect(creator.useElementTitles).toEqual(false);
});

test("Test showTitlesInExpressions <> useElementTitles compatibility", () => {
  const creator = new CreatorTester();
  creator.useElementTitles = true;
  expect(creator.showTitlesInExpressions).toEqual(true);
  creator.showTitlesInExpressions = false;
  expect(creator.useElementTitles).toEqual(false);
});

test("Test maximumChoicesCount <> maxChoices compatibility", () => {
  const creator = new CreatorTester();
  creator.maximumChoicesCount = 5;
  expect(creator.maxChoices).toEqual(5);
  creator.maxChoices = 3;
  expect(creator.maximumChoicesCount).toEqual(3);
});

test("Test minimumChoicesCount <> minChoices compatibility", () => {
  const creator = new CreatorTester();
  creator.minimumChoicesCount = 5;
  expect(creator.minChoices).toEqual(5);
  creator.minChoices = 3;
  expect(creator.minimumChoicesCount).toEqual(3);
});

test("Test maximumColumnsCount <> maxColumns compatibility", () => {
  const creator = new CreatorTester();
  creator.maximumColumnsCount = 5;
  expect(creator.maxColumns).toEqual(5);
  creator.maxColumns = 3;
  expect(creator.maximumColumnsCount).toEqual(3);
});

test("Test maximumRateValues <> maxRateValues compatibility", () => {
  const creator = new CreatorTester();
  creator.maximumRateValues = 5;
  expect(creator.maxRateValues).toEqual(5);
  creator.maxRateValues = 3;
  expect(creator.maximumRateValues).toEqual(3);
});

test("Test allowEditExpressionsInTextEditor <> logicAllowTextEditExpressions compatibility", () => {
  const creator = new CreatorTester();
  creator.allowEditExpressionsInTextEditor = false;
  expect(creator.logicAllowTextEditExpressions).toEqual(false);
  creator.logicAllowTextEditExpressions = true;
  expect(creator.allowEditExpressionsInTextEditor).toEqual(true);
});

test("Test showSurveyTitle <> showSurveyHeader compatibility", () => {
  const creator = new CreatorTester();
  creator.showSurveyTitle = false;
  expect(creator.showSurveyHeader).toEqual(false);
  creator.showSurveyHeader = true;
  expect(creator.showSurveyTitle).toEqual(true);
});

test("Test isAutoSave <> autoSaveEnabled compatibility", () => {
  const creator = new CreatorTester();
  creator.isAutoSave = true;
  expect(creator.autoSaveEnabled).toEqual(true);
  creator.autoSaveEnabled = false;
  expect(creator.isAutoSave).toEqual(false);
});

test("Test maxLogicItemsInCondition <> logicMaxItemsInCondition compatibility", () => {
  const creator = new CreatorTester();
  creator.maxLogicItemsInCondition = 4;
  expect(creator.logicMaxItemsInCondition).toEqual(4);
  creator.logicMaxItemsInCondition = 2;
  expect(creator.maxLogicItemsInCondition).toEqual(2);
});

test("Test showPagesInPreviewTab <> previewAllowSelectPage compatibility", () => {
  const creator = new CreatorTester();
  creator.showPagesInPreviewTab = false;
  expect(creator.previewAllowSelectPage).toEqual(false);
  creator.previewAllowSelectPage = true;
  expect(creator.showPagesInPreviewTab).toEqual(true);
});

test("Test showSimulatorInPreviewTab <> previewAllowSelectPage compatibility", () => {
  const creator = new CreatorTester();
  creator.showSimulatorInPreviewTab = false;
  expect(creator.previewAllowSimulateDevices).toEqual(false);
  creator.previewAllowSimulateDevices = true;
  expect(creator.showSimulatorInPreviewTab).toEqual(true);
});

test("Test showDefaultLanguageInPreviewTab <> previewAllowSelectPage compatibility", () => {
  const creator = new CreatorTester();
  creator.showDefaultLanguageInPreviewTab = false;
  expect(creator.previewAllowSelectLanguage).toEqual(false);
  creator.previewAllowSelectLanguage = "auto";
  expect(creator.showDefaultLanguageInPreviewTab).toEqual("auto");
  creator.showDefaultLanguageInPreviewTab = "all";
  expect(creator.previewAllowSelectLanguage).toEqual("all");
});

test("Test showInvisibleElementsInPreviewTab <> previewAllowSelectPage compatibility", () => {
  const creator = new CreatorTester();
  creator.showInvisibleElementsInPreviewTab = false;
  expect(creator.previewAllowHiddenElements).toEqual(false);
  creator.previewAllowHiddenElements = true;
  expect(creator.showInvisibleElementsInPreviewTab).toEqual(true);
});

test("Test makeNewViewActive (obsolete)", (): any => {
  const creator = new CreatorTester();
  expect(creator.makeNewViewActive("preview"));
  expect(creator.activeTab).toEqual("preview");
  expect(creator.makeNewViewActive("designer"));
  expect(creator.activeTab).toEqual("designer");
});